<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>公司职员管理</title>
    <link rel="stylesheet" href="../../js/bower_components/bootstrap/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../js/bower_components/bootstrap-select/dist/css/bootstrap-select.min.css">
    <link rel="stylesheet"
        href="../../js/bower_components/bootstrap-switch/dist/css/bootstrap3/bootstrap-switch.min.css">
    <link rel="stylesheet" href="../../js/bower_components/bootstrap-table/dist/bootstrap-table.min.css">
    <link rel="stylesheet" href="../../js/bower_components/bootstrap-treeview/dist/bootstrap-treeview.min.css">

    <script src="../../js/bower_components/jquery/dist/jquery.min.js"></script>
    <script src="../../js/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="../../js/bower_components/bootbox.min.js"></script>
    <script src="../../js/bower_components/bootstrap-select/js/bootstrap-select.js"></script>
    <script src="../../js/bower_components/bootstrap-switch/dist/js/bootstrap-switch.min.js"></script>
    <script src="../../js/bower_components/bootstrap-table/dist/bootstrap-table.min.js"></script>
    <script src="../../js/bower_components/bootstrap-table/dist/locale/bootstrap-table-zh-CN.js"></script>

    <script src="../../js/bower_components/bootstrap-treeview/dist/bootstrap-treeview.min.js"></script>
    <script src="../../js/bower_components/jquery-form-validator/form-validator/jquery.form-validator.min.js"></script>
    <script src="../../js/bower_components/moment/min/moment-with-locales.min.js"></script>
    <script>
        $(function () {
            $("#btnAdd").click(function () {
                console.log("模态框的打开方法===1");
                $("#divForm").modal();
                console.log("模态框的打开方法===2");
            })
            //搜索按钮
            $("#btnSearch").click(function () {
                console.log("进入搜索按钮的方法");
                //获取界面当中的控件的值
                var formempno = $("#txtempno").val();
                console.log(formempno);
                var formdept = $("#seldept").selectpicker('val');
                console.log(formdept);
                //整理查询条件
                var user = "?";
                if (formempno != "") {
                    user += "empno=" + formempno
                    if (formdept != "" || formdept != "全部") {
                        user += "&dept=" + formdept
                    }
                }
                else if (formdept != "") {
                    if (formdept != "全部") {
                        if (user != "") {
                            user += "&dept=" + formdept
                        } else {
                            user += "dept=" + formdept
                        }
                    }
                }

                console.log(user);

                //到后端去查询

                $.ajax({
                    type: "get",
                    dataType: "json",
                    url: "http://121.37.241.58:8883/logic/baseInfo/employee/find" + user,
                    success: function (res) {
                        inittable(res);
                    }
                })
            })

            initdept();
            inittable("");
            initdeptForm();
        });

        function initdept() {
            $("#seldept").empty;
            $.ajax({
                type: "get",
                url: "http://121.37.241.58:8883/logic/baseInfo/employee/deptList",
                dataType: "json",
                success: function (res) {
                    console.log(res);
                    if (!res.flag) {
                        $.each(res, function (i, n) {
                            $("#seldept").append("<option value=\"" + n.dept + "\">" + n.dept + "</option>")
                        });
                        $("#seldept").append("<option value='全部'>全部</option>");
                        $("#seldept").selectpicker('refresh');
                    }
                }
            })
        }


        function initdeptForm() {
            $("#seldeptForm").empty;
            $.ajax({
                type: "get",
                url: "http://121.37.241.58:8883/logic/baseInfo/employee/deptList",
                dataType: "json",
                success: function (res) {
                    console.log(res);
                    if (!res.flag) {
                        $.each(res, function (i, n) {
                            $("#seldeptForm").append("<option value=\"" + n.dept + "\">" + n.dept + "</option>")
                        });
                        $("#seldeptForm").selectpicker('refresh');
                    }
                }
            })
        }


        function inittable(myData) {
            console.log(myData + ":默认值")
            $("#tblResult").bootstrapTable("destroy");
            var formempno = $("#txtempno").val();
            var formdept = $("#seldept").selectpicker('val');
            if (myData == "") {
                if (formempno == "" || formdept == "") {
                    console.log("进入无参的方法")
                    $("#tblResult").bootstrapTable({
                        loadMsg: "正在加载数据....",
                        url: "http://121.37.241.58:8883/logic/baseInfo/employee/find",
                        //data:res,
                        sidePagination: 'client',
                        pageSize: "5",
                        Pageinatin: true,
                        idField: "id",
                        columns: [{
                            field: "empno",
                            title: "员工编号",
                            halign: 'center'
                        }, {
                            field: "namecn",
                            title: "员工姓名",
                            halign: 'center'
                        }, {
                            field: "dept",
                            title: "所在部门",
                            halign: 'center'
                        }, {
                            field: "reportto",
                            title: "上级ID",
                            halign: 'center'
                        }]

                    })
                } else {
                    console.log("进入无参的方法")

                    $("#tblResult").bootstrapTable({
                        loadMsg: "正在加载数据....",
                        //url:"http://121.37.241.58:8883/logic/baseInfo/employee/find",
                        data: myData,
                        sidePagination: 'client',
                        pageSize: "5",
                        Pageinatin: true,
                        idField: "id",
                        columns: [{
                            field: "empno",
                            title: "员工编号",
                            halign: 'center'
                        }, {
                            field: "namecn",
                            title: "员工姓名",
                            halign: 'center'
                        }, {
                            field: "dept",
                            title: "所在部门",
                            halign: 'center'
                        }, {
                            field: "reportto",
                            title: "上级ID",
                            halign: 'center'
                        }]
                    })
                }
            } else {
                console.log("进入条件查询");
                $("#tblResult").bootstrapTable({
                    loadMsg: "正在加载数据....",
                    //url:"http://121.37.241.58:8883/logic/baseInfo/employee/find",
                    data: myData,
                    sidePagination: 'client',
                    pageSize: "5",
                    Pageinatin: true,
                    idField: "id",
                    columns: [{
                        field: "empno",
                        title: "员工编号",
                        halign: 'center'
                    }, {
                        field: "namecn",
                        title: "员工姓名",
                        halign: 'center'
                    }, {
                        field: "dept",
                        title: "所在部门",
                        halign: 'center'
                    }, {
                        field: "reportto",
                        title: "上级ID",
                        halign: 'center'
                    }]
                })
            }
        }
    </script>


</head>

<body>
    <div class="container-flempno">
        <!--查询区域-->
        <div calss="row col-md-10">
            <div id="SearchForm" class="form-inline">
                <div class="input-group">
                    <label for="txtempno" class="control-label">员工编号</label>
                    <input type="text" id="txtempno" />
                </div>
                <div class="input-group">
                    <label class="control-label" for="seldept">所在部门</label>
                    <select id="seldept"></select>
                </div>
                <div class="form-group">
                    <button type="button" id="btnSearch" class="btn btn-primary">检索</button>
                </div>
            </div>
        </div>
        <!--功能区域-->
        <div style="margin-top: 5px;" class="form-inline">
            <div id="btnTools">
                <button type="button" id="btnAdd" class="btn btn-success">新增</button>
            </div>
        </div>
        <!--列表区域-->
        <div class="row col-md-10">
            <table id="tblResult"></table>

        </div>
    </div>

    <!--模态框的使用-->
    <div class="modal fade" id="divForm" tabindex="-1" dept="dialog" aria-labelledby="myModal" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="modalTitle">新增资产</h4>
                </div>
                <div class="modal-body form-inline">
                    <div class="form-group">
                        <label class="control-label" for="txtempnoForm">员工编号</label>
                        <input type="text" id="txtempnoForm" style="width: 200px;" class="form-control" />
                    </div>
                    <div class="form-group">
                        <label class="control-label" for="txtnamecn">员工姓名</label>
                        <input type="text" id="txtnamecn" style="width: 200px;" class="form-control" />
                    </div>
                    <div class="form-group">
                        <label class="control-label" for="seldeptForm">所在部门</label>
                        <select id="seldeptForm"></select>
                    </div>

                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary">保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>

</html>